package com.server.http.anYuan;


import com.alibaba.fastjson2.JSONObject;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

public class AnYuanDto {
    private AnYuanDto(){}

    public JSONObject data;
    private static JSONObject trim(String text) throws Exception {
        text = text.trim();
        text = URLDecoder.decode(text, "UTF-8");
        if (text.endsWith("=")) {
            text = text.substring(0, text.length() - 1);
        }
        return JSONObject.parseObject(text);
    }


    public static AnYuanDto from(String text) throws Exception {
        JSONObject data = trim(text);
        AnYuanDto anYuanDto = new AnYuanDto();
        anYuanDto.data = data;
        return anYuanDto;
    }


    public Map<String,Object> OK(){
        Map<String, Object> var = new HashMap<>();
        var.put("com", data.getInteger("com"));
        var.put("return", 0);
        var.put("message", "ok");
        return var;
    }

    public Map<String,Object> OK(Map<String,Object> msg){
        Map<String, Object> var = new HashMap<>();
        var.put("com", data.getInteger("com"));
        var.put("return", 0);
        var.put("message", "ok");
        var.putAll(msg);
        return var;
    }

    public Map<String,Object> NO(String msg){
        Map<String, Object> var = new HashMap<>();
        var.put("com", data.getInteger("com"));
        var.put("return", 1);
        var.put("message", msg);
        return var;
    }
}

